package com.rjwh.dingdong.client.mvp.model.impl;

import com.aishua.lib.task.AsResult;
import com.rjwh.dingdong.client.application.MyApplication;
import com.rjwh.dingdong.client.constant.LocalConstant;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BaseModel;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.IUserRegisterCodeModel;
import com.rjwh.dingdong.client.network.HttpWebService;
import com.rjwh.dingdong.client.network.HttpWebServiceCallBack;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Kay
 * @ClassName UserRegisterCodeModel
 * @Description
 * @date 2016-7-30
 * @history 2016-7-30 author: description:
 */
public class UserRegisterCodeModel extends BaseModel implements IUserRegisterCodeModel, HttpWebServiceCallBack {

    public UserRegisterCodeModel(BasePresenter basePresenter) {
        super(basePresenter);
    }

    /**
     * 获取验证码
     *
     * @param inputPhone 手机号
     */
    @Override
    public void doGetCode(String inputPhone) {
        Map<String, String> params = new HashMap<>();
        params.put("userid", MyApplication.spUtil.getStrPreferenceByParamName(MyApplication.app, LocalConstant.SP_USERID));
        params.put("phone", inputPhone);
        params.put("type", "2");
        HttpWebService.getDataFromServer(NetConstant.TYPE_SMS_CODE, params, true, this);
    }

    /**
     * 校验验证码
     *
     * @param inputPhone 手机号
     * @param codeInput  验证码
     */
    @Override
    public void doCheckCode(String inputPhone, String codeInput) {
        Map<String, String> params = new HashMap<>();
        params.put("phone", inputPhone);
        params.put("verifycode", codeInput);
        params.put("type", "2");
        HttpWebService.getDataFromServer(NetConstant.TYPE_CONFIRM_SMS_CODE, params, true, this);
    }

    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if (getBasePresenter() != null) {
            getBasePresenter().onServerDataAcquired(businessType, mAsResult, isRefresh);
        }
    }
}
